08. Comprehensive Metrics for a Diversified Portfolio Demo
Part 1 - Calculating the Sortino Ratio
PRDTM2-786 AI Trading C3 L3 8 Comprehensive Metrics For A Diversified Portfolio Demo Pt1
Analyzing a Diversified Portfolio in Python
This lesson teaches how to calculate and visualize metrics for a simple diversified portfolio using Python. Focus is on the Sortino Ratio and Calmar Ratio.
Key Steps Covered:
Data Preparation
- Use
yfinanceto download historical price data for selected assets. - Example: SPY ETF (stocks) and IEF ETF (bonds) for a 60/40 portfolio from January 1st to December 31st, 2023.
- Use
Calculate Daily Returns
- Compute daily returns using the percentage change method.
- Weighted portfolio returns (60% SPY and 40% IEF).
Calculate Metrics
- Sortino Ratio:
- Determine annualized return by scaling daily returns.
- Adjust by the risk-free rate, fetched with
yfinance. - Calculate downside volatility and derive the Sortino Ratio.
- Example Result: A Sortino Ratio of 2.1, indicating favorable performance.
Next Steps
- Explore calculations for the Calmar Ratio in the upcoming lesson.
Part 2 - Calculating the Calmar Ratio
PRDTM2-786 AI Trading C3 L3 9 Comprehensive Metrics For A Diversified Portfolio Demo Pt2
Guide to Calculating the Calmar Ratio
Learn how to compute the Calmar Ratio, an essential tool for assessing the risk-adjusted performance of a portfolio.
Steps to Follow:
Cumulative Return
- Calculate cumulative returns using:
Cumulative Return = (1 + Portfolio Returns).cumulative product
Cumulative Maximum
- Determine cumulative maxima by finding the maximum cumulative return.
Ongoing Drawdown
- Compute the drawdown percentage:
Drawdown = (Cumulative Max - Cumulative Return) / Cumulative Max
Maximum Drawdown
- Identify the largest drawdown from the ongoing drawdowns.
Calmar Ratio Calculation
- Derive the Calmar Ratio using:
Calmar Ratio = Annualized Return / Maximum Drawdown
Outcome
- Achieving a Calmar Ratio of 2 suggests the portfolio had favorable conditions in 2023. The drawdown percentage was significantly lower than the annualized return, verifying the portfolio’s robustness.
Part 3 - Refining the Plot
PRDTM2-786 AI Trading C3 L3 10 Comprehensive Metrics For A Diversified Portfolio Demo Pt3
Creating Enhanced Plots for Portfolio Analysis
This guide focuses on refining and interpreting financial plots for an investment portfolio analysis, specifically cumulative returns and drawdowns.
Plotting Cumulative Returns
- Start with a basic plot to verify numbers.
- Adjust figure size to find optimal display: tested 10x10, 8x8, 6x6, and settled on 6x4 for clarity.
- Label the plot for easy interpretation.
Visualizing Drawdowns
- Use "fill between" method to indicate drawdown areas.
- X-axis: Cumulative return index.
- Y-axis: Difference between maximum and current cumulative returns.
- Adjust "alpha" to make drawdown areas visually clearer, opting for a light blue shade.
Enhancing Clarity
- Legend and grid added for better readability.
- Adjust opacity for better visualization with
alpha levels like 0.2 or 0.3.
Financial Implications
- Plots help assess how each dollar invested performs over time, indicating potential losses at specific points.
- Analyze risk-reward ratio using metrics like the Sortino and Calmar ratios.
This concludes the exercise in understanding cumulative returns and drawdowns, aiming for better portfolio management and strategy insights.